Page({
  data: {
    page: 0,
    page_size: 20,
    store_id: 0,
    store: [],
    items: [],
    goods: [],
  },
  onLoad(query) {
    var app = getApp();
    var url = app.globadData.apiUrlHeader + 'get-store-index';
    var store_id = query['query'];
    this.setData({store_id: store_id});
    my.httpRequest({
      url: url, // 目标服务器 url
      method: 'POST',
      type: 'Json',
      headers: {'Content-Type': 'Application/json'},
      data: JSON.stringify({'access_token': app.globadData.access_token, 'store_id': store_id}),
      success: (res) => {
        if (res.data.status == '0') {
          this.setData({
            store: res.data.data.store,
            items: res.data.data.items,
          });
        }
      },
    });
    this.getGoodsList();
  },
  getGoodsList() {
    var app = getApp();
    var url = app.globadData.apiUrlHeader + 'get-store-goods-list';
    my.httpRequest({
      url: url,
      method: 'POST',
      type: 'JSON',
      headers: {'Content-Type': 'Application/json'},
      data: JSON.stringify({
        'access_token': app.globadData.access_token,
        'store_id': this.data.store_id,
        'page': this.data.page,
        'page_size': this.data.page_size
      }),
      success: (res) => {
        if (res.data.status == 0) {
          this.setData({
            goods: this.data.goods.concat(res.data.data),
            page: this.data.page++,
          });
        }
      }
    });
  },
  loadMore() {
    this.getGoodsList();
  },
  redirectStoreDetail(e) {
    var id = e.target.dataset.id;
    my.redirectTo({url: '/pages/main/store-detail/store-detail?query=' + id});
  }
});
